<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jquery-3.3.1.min.js"></script>
</head>

<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <script>
        $(function() {
            var sum = 0;
            // $("div").css("color", "red");
            var arr = ["red", "blue", "green"];
            $("div").each(function(index, domEle) {
                //console.log(index);
                $(domEle).css("color", arr[index]);
                sum += parseInt($(domEle).text());
            })
            console.log(sum);
            //$.each()方法遍历元素 主要用于遍历数据，处理数据
            //主要遍历数组/对象
            $.each($("div"), function(i, ele) {
                console.log(i);
                console.log(ele);
            })
        })
    </script>
</body>

</html>